﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections;
using Luminji.Core.Data;

namespace Luminji.ExamExchange
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
            SqlHelper.ConnectionString = _conn;
            this.WindowState = WindowState.Maximized;
        }

        private string _conn = "Data Source=192.168.0.192;Initial Catalog=wangyuanban;User Id=sa;Password=tongkao2008;";

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            
        }

        private void Reflesh_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DataSet ds;
                string sql = @"select a.*, c.*,b.*, d.Name AS pName 
                from Exam_Contract a inner join Pp_paper b on a.[PaperCode]=b.Code 
                    inner join Exam_subject c on a.subjectCode = c.Code  
                    INNER JOIN dbo.Pp_Paper d ON a.PaperCode = d.Code 
                where PaperType = 'lianxi' ORDER BY  Name ,BatchId, QuestionNo";
                ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionString, CommandType.Text, sql);
                IList il = (ds.Tables[0] as IListSource).GetList();
                IList il2 = new ArrayList();
                for (int i = 0; i < 10; i++)
                {
                    il2.Add(il[i]);
                }
                this.dataGridOld.ItemsSource = il2;

                SqlHelper.ConnectionString = "Data Source=192.168.0.96;Initial Catalog=ExamWeb;User Id=sa;Password=tingzi0201;";
                sql = @"SELECT * FROM dbo.Paper";
                ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionString, CommandType.Text, sql);
                IList il3 = (ds.Tables[0] as IListSource).GetList();
                this.dataGridPaperNew.ItemsSource = il3;

                sql = @"SELECT * FROM dbo.PaperDetail";
                ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionString, CommandType.Text, sql);
                IList il4 = (ds.Tables[0] as IListSource).GetList();
                IList il5 = new ArrayList();
                for (int i = 0; i < 10 && i < il4.Count; i++)
                {
                    il5.Add(il[4]);
                }
                this.dataGridNew.ItemsSource = il5;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
    }
}
